var snowmax = 100; // flakes on screen
var snowcolor = ["#fff", "#fafafa", "#d9ecff"]; // flake color
var snowletter = "&#10052;";
var sinkspeed = 1; // fall speed
var snowmaxsize = 50; // flake max size
var snowminsize = 10; // flake min size
var snow = [];
var marginbottom = window.innerHeight;
var marginright = window.innerWidth;

var x_mv = [];
var crds = [];
var lftrght = [];

function randommaker(range) {
    rand = Math.floor(range * Math.random());
    return rand;
}

window.onload = function () {
    var snowsizerange = snowmaxsize - snowminsize;
    for (var i = 0; i <= snowmax; i++) {
        crds[i] = 0;
        lftrght[i] = Math.random() * 15;
        x_mv[i] = 0.03 + Math.random() / 10;

        var flake = document.createElement('span');
        //var stuff
        flake.size = randommaker(snowsizerange) + snowminsize;
        flake.sink = sinkspeed * flake.size / 5;
        //css stuff
        flake.style.fontSize = flake.size + 'px';
        flake.style.color = snowcolor[randommaker(snowcolor.length)];
        flake.innerHTML = snowletter;

        flake.posx = randommaker(marginright - flake.size);
        flake.posy = randommaker(marginbottom - 2 * flake.size);
        flake.style.left = flake.posx + 'px';
        flake.style.top = flake.posy + 'px';
        //attr stuff
        flake.id = 's' + i;
        flake.className = 'flake';
        snow[i] = flake;
        document.getElementById('snow').appendChild(flake);
    }
    movesnow();
};

window.onresize = function () {
    marginbottom = window.innerHeight;
    marginright = window.innerWidth;
};

function movesnow() {
    for (var i = 0; i <= snowmax; i++) {
        crds[i] += x_mv[i];
        snow[i].posy += snow[i].sink;
        var posx = snow[i].posx + lftrght[i] * Math.sin(crds[i]);
        var posy = snow[i].posy;
        snow[i].style.left = posx + 'px';
        snow[i].style.top = posy + 'px';

        if (snow[i].posy >= marginbottom - 2 * snow[i].size || parseInt(snow[i].style.left) > (marginright - 3 * lftrght[i])) {
            snow[i].posx = randommaker(marginright - snow[i].size);
            snow[i].posy = 0;
        }
    }
    setTimeout(movesnow, 50);
}